<template>
	<view>
		<u-navbar title="我的钱包" :autoBack="true" :bgColor="theme_color" :titleStyle="{color:'#ffffff'}"
			leftIconColor="#ffffff"></u-navbar>
		<view class='my-account' :style="'margin-top:' + navH + 'px;'">
			<view class='wrapper'>
				<view class='header'>
					<view class='headerCon'>
						<view class='account acea-row row-top row-between'>
							<view class='assets'>
								<view>可使用余额(元)</view>
								<view class='money'>{{walletInfo.user_money || 0}}</view>
							</view>

							<view>
								<view @click="openSubscribe('/pages/users/user_payment/index')" class='recharge'>充值
								</view>
								<view class="account-grid" @click="navTo('/pages/users/withdraw/index')">
									<span class="account-grid-comm-sign">立即提现</span>
								</view>
							</view>
						</view>
						<view class='cumulative acea-row row-top'>
							<!-- #ifdef MP -->
							<view class='item'>
								<view>冻结金额(元)</view>
								<view class='money'>{{walletInfo.frozen_money || 0}}</view>
							</view>
							<!-- #endif -->
							<view class='item'>
								<view>积分</view>
								<view style="color: white;font-size: 48rpx;margin-top: 6rpx;">{{walletInfo.pay_points || 0}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class='nav acea-row row-middle'>
					<navigator class='item' hover-class='none' url='/pages/users/user_bill/index'>
						<view class='iconfont icon-s-zhangdanjilu'></view>
						<view>账单记录</view>
					</navigator>
					<navigator class='item' hover-class='none' url='/pages/users/user_bill/index?type=1'>
						<view class='iconfont icon-s-xiaofeijilu'></view>
						<view>消费记录</view>
					</navigator>
					<navigator class='item' hover-class='none' url='/pages/users/user_bill/index?type=2'
						v-if="recharge_switch">
						<view class='iconfont icon-s-chongzhijilu'></view>
						<view>充值记录</view>
					</navigator>
					<navigator class='item' hover-class='none' url='/pages/users/user_integral/index'>
						<view class='iconfont icon-jifenzhongxin'></view>
						<view>积分中心</view>
					</navigator>
				</view>
			</view>
		</view>
		<view class="top">
			<u-subsection :list="tabs" fontSize="16" activeColor="#009a00" :current="tabIndex" @change="changeTab">
			</u-subsection>
		</view>
		<view class="list-view">
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption">
				<view class="list-item" v-for="(item, index) in list" :key="index" hover-class="hover"
					:hover-stay-time="150" bindtap="detail">
					<view class="content-box">
						<view class="des-box">
							<view class="tit">
								<block v-if="tabIndex == 0">{{item.change_desc}}</block>
								<block v-if="tabIndex == 1">充值方式:
									<block v-if="item.pay_type == null">暂无</block>
									<block v-if="item.pay_type == 'wechat'">微信</block>
									<block v-if="item.pay_type == 'alipay'">支付宝</block>
								</block>
								<block v-if="tabIndex == 2">
									<view :style="{ color: item.status == 0 ? '#4caf50' : item.status == 1 ? '#00b7ff' : '#ff1e0f' }" style="font-size: 32rpx;">
										<block v-if="item.status == 0">提现申请中</block>
										<block v-if="item.status == 1">已同意提现，等待打款</block>
										<block v-if="item.status == 2">拒绝申请</block>
										<block v-if="item.status == 3">已提现到账</block>
									</view>
								</block>
							</view>
							<view v-if="tabIndex == 0" class="source" style="color: #4caf50;">
								{{ item.change_type || '' }}
							</view>
							<view v-if="tabIndex == 1" class="source" style="color: #4caf50;">
								流水号:{{ item.order_sn }}
							</view>
							<view v-if="tabIndex == 2" class="source" :style="{ color: item.status == 0 ? '#4caf50' : item.status == 1 ? '#00b7ff' : '#ff1e0f' }">
								<!-- <block v-if="item.status == 0">提现申请中</block>
								<block v-if="item.status == 1">已同意提现，等待打款</block>
								<block v-if="item.status == 2">拒绝申请</block>
								<block v-if="item.status == 3">已提现到账</block> -->
							</view>
							<view class="time source">
								<block v-if="tabIndex == 0">{{ item.change_time }}</block>
								<block v-if="tabIndex == 1">{{ item.add_time }}</block>
								<block v-if="tabIndex == 2">{{ item.create_time }}</block>
							</view>
						</view>
					</view>
					<view class="money" :class="{ less: tabIndex == 2 }" v-if="tabIndex != 0">
						{{ tabIndex == 2 ? '-' : '+' }}{{item.amount }}
					</view>
					<view style="text-align: right;" v-else>
						<view style="min-height: 20px;" class="source">积分:{{item.pay_points }}</view>
						<view style="min-height: 20px;" class="source">变动金额:{{item.user_money}}</view>
						<view style="min-height: 20px;" class="source">冻结金额:{{item.frozen_money}}</view>
					</view>
				</view>
			</mescroll-body>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		userInfo,
		wallet,
		withdraw_log,
		recharge_log,
		account_log
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				walletInfo: {
					frozen_money:'',
					pay_points:0,
					user_money:''
				},
				userInfo: {},
				navH: '',
				theme_color: getApp().globalData.theme_color,
				tabs: ['账户明细', '充值记录', '提现记录'],
				tabIndex: 0,
				start_time: '',
				end_time: '',
				list: [],
				upOption:{
					textNoMore:'暂无更多数据',
					empty:{
						tip:'暂无更多数据'
					}
				}
			};
		},
		computed: mapGetters(['isLogin', 'app_token']),
		onLoad() {
			this.navH = getApp().globalData.navHeight / 2;
			
		},
		onShow() {
			if (this.isLogin) {
				this.getUserInfo();
				this.getWallet();
			} else {
				toLogin();
			}
		},
		methods: {
			upCallback(page) {
				var that = this;
				if (that.tabIndex == 2) {
					withdraw_log({
						app_token: that.app_token,
						page: page.num,
						start_time: that.start_time,
						end_time: that.end_time
					}).then(async (res) => {

						this.mescroll.endSuccess(res.data.length);

						//设置列表数据
						if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list = this.list.concat(res.data); //追加新数据

					}).catch(() => {
						//联网失败, 结束加载
						this.mescroll.endErr();
					})

				} else if (that.tabIndex == 1) {
					recharge_log({
						app_token: that.app_token,
						page: page.num,
						start_time: that.start_time,
						end_time: that.end_time
					}).then(async (res) => {

						this.mescroll.endSuccess(res.data.length);

						//设置列表数据
						if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list = this.list.concat(res.data); //追加新数据

					}).catch(() => {
						//联网失败, 结束加载
						this.mescroll.endErr();
					})
				} else if (that.tabIndex == 0) {
					account_log({
						app_token: that.app_token,
						page: page.num,
						start_time: that.start_time,
						end_time: that.end_time,
						type: ''
					}).then(async (res) => {

						this.mescroll.endSuccess(res.data.length);

						//设置列表数据
						if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
						this.list = this.list.concat(res.data); //追加新数据

					}).catch(() => {
						//联网失败, 结束加载
						this.mescroll.endErr();
					})
				}

			},
			// #ifdef MP
			openSubscribe: function(page) {
				uni.navigateTo({
					url: page,
				});
			},
			// #endif
			/**
			 * 获取用户详情
			 */
			getUserInfo: function() {
				let that = this;
				userInfo({
					app_token: that.app_token
				}).then(res => {
					that.$set(that, 'userInfo', res.data);
				});
			},
			getWallet: function() {
				let that = this;
				wallet({
					app_token: that.app_token
				}).then(res => {
					that.$set(that, 'walletInfo', res.data);
				});
			},
			navTo(url) {
				uni.navigateTo({
					url
				});
			},
			changeTab(index) {
				this.tabIndex = index;
				this.mescroll.resetUpScroll()
			},
		},

	}
</script>

<style scoped lang="scss">
	.my-account .wrapper {
		background-color: #fff;
		padding: 32rpx 0 34rpx 0;
		margin-bottom: 14rpx;
	}

	.my-account .wrapper .header {
		width: 690rpx;
		height: 330rpx;
		background-image: linear-gradient(to right, #e93323 0%, #f36053 100%);
		// background-image: #e93323;
		// background: #e93323;
		border-radius: 16rpx;
		margin: 0 auto;
		box-sizing: border-box;
		color: rgba(255, 255, 255, 0.6);
		font-size: 24rpx;
	}

	.my-account .wrapper .header .headerCon {
		background-image: url('');
		background-repeat: no-repeat;
		background-size: 100%;
		height: 100%;
		width: 100%;
		padding: 36rpx 0 29rpx 0;
		box-sizing: border-box;
	}

	.my-account .wrapper .header .headerCon .account {
		.assets {
			margin-left: 35rpx;
		}
	}

	.my-account .wrapper .header .headerCon .account .assets .money {
		font-size: 72rpx;
		color: #fff;
		font-family: 'Guildford Pro';
	}

	.my-account .wrapper .header .headerCon .account .recharge {
		margin-right: 35rpx;
		font-size: 28rpx;
		width: 150rpx;
		height: 54rpx;
		border-radius: 27rpx;
		background-color: #fff9f8;
		text-align: center;
		line-height: 54rpx;
		color: #e93323;
	}

	.my-account .wrapper .header .headerCon .cumulative {
		margin-top: 46rpx;
	}

	.my-account .wrapper .header .headerCon .cumulative .item {
		flex: 1;
		padding-left: 35rpx;
	}

	.my-account .wrapper .header .headerCon .cumulative .item .money {
		font-size: 48rpx;
		font-family: 'Guildford Pro';
		color: #fff;
		margin-top: 6rpx;
	}

	.my-account .wrapper .nav {
		height: 155rpx;
		border-bottom: 1rpx solid #f5f5f5;
	}

	.my-account .wrapper .nav .item {
		flex: 1;
		text-align: center;
		font-size: 26rpx;
		color: #999;
	}

	.my-account .wrapper .nav .item .iconfont {
		font-size: 44rpx;
		margin: 0 auto;
		margin-bottom: 14rpx;
		color: #e93323;
	}

	.my-account .wrapper .advert {
		padding: 0 30rpx;
		margin-top: 30rpx;
	}

	.my-account .wrapper .advert .item {
		background-color: #fff6d1;
		width: 332rpx;
		height: 118rpx;
		border-radius: 10rpx;
		padding: 0 27rpx 0 25rpx;
		box-sizing: border-box;
		font-size: 24rpx;
		color: #e44609;
	}

	.my-account .wrapper .advert .item.on {
		background-color: #fff3f3;
		color: #e96868;
	}

	.my-account .wrapper .advert .item .pictrue {
		width: 78rpx;
		height: 78rpx;
	}

	.my-account .wrapper .advert .item .pictrue image {
		width: 100%;
		height: 100%;
	}

	.my-account .wrapper .advert .item .text .name {
		font-size: 30rpx;
		font-weight: bold;
		color: #f33c2b;
		margin-bottom: 7rpx;
	}

	.my-account .wrapper .advert .item.on .text .name {
		color: #f64051;
	}

	.my-account .wrapper .list {
		padding: 0 30rpx;
	}

	.my-account .wrapper .list .item {
		margin-top: 44rpx;
	}

	.my-account .wrapper .list .item .picTxt .iconfont {
		width: 82rpx;
		height: 82rpx;
		border-radius: 50%;
		background-image: linear-gradient(to right, #ff9389 0%, #f9776b 100%);
		text-align: center;
		line-height: 82rpx;
		color: #fff;
		font-size: 40rpx;
	}

	.my-account .wrapper .list .item .picTxt .iconfont.yellow {
		background-image: linear-gradient(to right, #ffccaa 0%, #fea060 100%);
	}

	.my-account .wrapper .list .item .picTxt .iconfont.green {
		background-image: linear-gradient(to right, #a1d67c 0%, #9dd074 100%);
	}

	.my-account .wrapper .list .item .picTxt {
		width: 428rpx;
		font-size: 30rpx;
		color: #282828;
	}

	.my-account .wrapper .list .item .picTxt .text {
		width: 317rpx;
	}

	.my-account .wrapper .list .item .picTxt .text .infor {
		font-size: 24rpx;
		color: #999;
		margin-top: 5rpx;
	}

	.my-account .wrapper .list .item .bnt {
		font-size: 26rpx;
		color: #282828;
		width: 156rpx;
		height: 52rpx;
		border: 1rpx solid #ddd;
		border-radius: 26rpx;
		text-align: center;
		line-height: 52rpx;
	}

	.my-account .wrapper .list .item .bnt.end {
		font-size: 26rpx;
		color: #aaa;
		background-color: #f2f2f2;
		border-color: #f2f2f2;
	}

	.account {
		&-grid {
			&-comm-sign {
				margin-top: 20rpx;
				display: block;
				border-radius: 40rpx 0 0 40rpx;
				font-size: 26rpx;
				padding: 16rpx 44rpx;
				background: linear-gradient(to right, #fef082, #ffc551);
				background-color: #fef082;
				color: #cf4400;
			}
		}
	}

	.list-view {
		position: relative;
		width: 100%;
		overflow: hidden;
	}

	.list-item {
		width: 100%;
		padding: 30rpx 28rpx;
		box-sizing: border-box;
		background: #fff;
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
		border-bottom: 1rpx solid #eaeef1;
	}

	.item-last::after {
		left: 0 !important;
	}

	.content-box {
		display: flex;
		align-items: flex-start;
		justify-content: space-between;
	}

	.des-box {
		color: #333;
		font-size: 28rpx;
		display: flex;
		flex-direction: column;
		view{
			min-height: 20px;
		}
	}

	.tit {
		font-size: 32rpx;
		max-width: 420rpx;
		// white-space: nowrap;
		// overflow: hidden;
		// text-overflow: ellipsis;
	}

	.source {
		margin: 12rpx 0;
	}

	.time {
		color: #888;
	}

	.money {
		font-size: 38rpx;
		font-weight: 500;
		color: #ff1e0f;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		padding-left: 20rpx;
	}

	.less {
		color: #4caf50 !important;
	}

	.tip {
		margin-top: 50rpx;
		display: flex;
		justify-content: center;
		align-content: center;
		font-size: 24rpx;
		color: #888;
	}
</style>
